package com.usian.controller;

import com.usian.pojo.CL;
import com.usian.pojo.User;
import com.usian.service.ClService;
import com.usian.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.List;

@Controller
@RequestMapping("/cl")
public class CLController {
    @Autowired
    private ClService clService;

//    private static final Logger logger= LoggerFactory.getLogger(ZhuceController.class);

//    @Autowired
//    private DruidDataSource druidDataSource;

//    @RequestMapping("/user")
//    public String User(){
//        return "我的第一个springboot项目";
//    }
//
//    @RequestMapping("/index")
//    public String index(Model model){
//        model.addAttribute("msg","您好");
//        return "index";
//    }
//
//    @RequestMapping("/emp/{id}")
//    public String emp(@PathVariable("id")String id,String name,Model model){
//        model.addAttribute("id",id);
//        model.addAttribute("name",name);
//        return "index";
//    }
//
//    @RequestMapping("testJunit")
//    @ResponseBody
//    public String testJunit(){
//        return "测试junit";
//    }


//    public static void main(String[] args) {
//        String username="abcdefghijklmnopqrstuvwxyz";
//        System.out.println(username.indexOf("e"));
//        String username1="abcdefghijklmneopqrstuvwxyz";
//        System.out.println(username1.lastIndexOf("e"));
//        System.out.println(username.substring(0,2));//从下标开始截取几个字符
//    }

    /**
     * 查询所有用户信息
     * @param model
     * @return
     */
    @RequestMapping("/findAll")
    public String findAll(Model model,CL cl){
        List<CL> clList=clService.findAll(cl);
        model.addAttribute("clList",clList);
        return "ETC";
    }
    /**
     * 管理员查询
     * @param model
     * @return
     */
    @RequestMapping("/findGL")
    public String findGL(Model model,CL cl){
        List<CL> clList=clService.findGL(cl);
        model.addAttribute("clList",clList);
        return "ETCGL";
    }

    @RequestMapping("/toAdd")
    public String toAdd(){
        return "addC";
    }

    @RequestMapping("/addCL")
    public String addCL(CL cl) {
        clService.addCL(cl);
        return "redirect:/cl/findAll";
    }
    @RequestMapping("/toEdit")
    public String toEdit(Integer id,Model model){
        CL cl=clService.editId(id);
        model.addAttribute("cl",cl);
        return "editC";
    }

    @RequestMapping("/editCL")
    public String editCL(CL cl){
        clService.editCL(cl);
        return "redirect:/cl/findAll";
    }
    @RequestMapping("/del")
    public String del(Integer id){
        clService.del(id);
        return "redirect:/cl/findAll";
    }

}
